package net.maku.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import net.maku.bean.query.WebPayRecordQuery;
import net.maku.bean.vo.WebPayRecordVO;
import net.maku.convert.WebPayRecordConvert;
import net.maku.entity.WebPayRecordEntity;
import net.maku.service.WebPayRecordService;
import net.maku.utils.PageResult;
import net.maku.utils.Result;

import org.springdoc.core.annotations.ParameterObject;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;
import java.util.List;

/**
* 支付信息表
*
* @author 阿沐 babamu@126.com
* @since 1.0.0 2024-09-02
*/
@RestController
@RequestMapping("maku/web_pay_record")
@Tag(name="支付信息表")
@AllArgsConstructor
public class WebPayRecordController {
    private final WebPayRecordService webPayRecordService;

    @GetMapping("page")
    @Operation(summary = "分页")
    //@PreAuthorize("hasAuthority('maku:web_pay_record:page')")
    public Result<PageResult<WebPayRecordVO>> page(@ParameterObject @Valid WebPayRecordQuery query){
        PageResult<WebPayRecordVO> page = webPayRecordService.page(query);

        return Result.ok(page);
    }

    @GetMapping("{id}")
    @Operation(summary = "信息")
    //@PreAuthorize("hasAuthority('maku:web_pay_record:info')")
    public Result<WebPayRecordVO> get(@PathVariable("id") Long id){
        WebPayRecordEntity entity = webPayRecordService.getById(id);

        return Result.ok(WebPayRecordConvert.INSTANCE.convert(entity));
    }

    @PostMapping
    @Operation(summary = "保存")
    //@PreAuthorize("hasAuthority('maku:web_pay_record:save')")
    public Result<String> save(@RequestBody WebPayRecordVO vo){
        webPayRecordService.save(vo);

        return Result.ok();
    }

    @PutMapping
    @Operation(summary = "修改")
    //@PreAuthorize("hasAuthority('maku:web_pay_record:update')")
    public Result<String> update(@RequestBody @Valid WebPayRecordVO vo){
        webPayRecordService.update(vo);

        return Result.ok();
    }

    @DeleteMapping
    @Operation(summary = "删除")
    //@PreAuthorize("hasAuthority('maku:web_pay_record:delete')")
    public Result<String> delete(@RequestBody List<Long> idList){
        webPayRecordService.delete(idList);

        return Result.ok();
    }
}